<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 变量提升 将变量的声明语句放在当前作用域的最上方 只声明不赋值 此时值是undefined
        var num = 100;
        num++;
        console.log(num);
        function fn1() {
            console.log(num);
            var num = 80; // 变量提升
            console.log(num);
        }
        fn1();
        console.log(num);

        console.log(fn2());
        // 先调用函数 后声明函数

        function fn2() {
            return 'function也会造成变量提升'
        }

        var a = 100;
        function fn3() {
            // debugger
            var a;
            var b;
            var c;
            b = 2 * a;  // 此时的a是undefined
            a = 200;
            c = a / 2;
            alert(b);
            alert(c);
        }

        fn3();
    </script>
</body>

</html>